package wheel.conversion.impl;

import wheel.conversion.Converter;

import java.util.Map;

public class IntegerConverter extends Converter {
    public Class getTargetClass() {
        return Integer.class;
    }
    
    public Object convert(String value, Map<String, String> params) {
        int radix = 10;
        if (params != null && 
                params.containsKey("$radix")) {
            try {
                radix = Integer.parseInt(params.get("$radix"));
            } catch (NumberFormatException nfe) {
                // NOOP
            }
        }
        
        try {
            return Integer.valueOf(value, radix);
        } catch (NumberFormatException nfe) {
            return null;
        }
    }
}
